package org.fatmansoft.teach.repository;

import org.fatmansoft.teach.models.Assessment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface AssessmentRepository extends JpaRepository<Assessment,Integer> {

    //查询方法
    //评价者的姓名学号
    //被评价者的姓名学号
    //对应get那个里面
    ////10.29   如果没有数据，就默认查找所有的学生
    //    //如果有数据，就查出对应学生


    //注意这个地方，student.num和student.name要与实体类中的属性对应起来
    @Query(value = "from Assessment where ?1='' or student.person.num like %?1% or student.person.name like %?1% ")
    List<Assessment> findAssessmentListByNumName(String NumName);
    @Query(value = "from Assessment where (?1='' or student.person.num like %?1% or student.person.name like %?1%) and (studentEvaluator.person.num like %?2% or studentEvaluator.person.name like %?2% )")
    List<Assessment> findStuAssessmentListByNumName(String NumName,String Username);

    @Query(value = "from Assessment where ?1='' or studentEvaluator.person.num like %?1% or studentEvaluator.person.name like %?1% ")
    List<Assessment> findAssessmentListByEvaluatorNumName(String NumName);
    @Query(value = "from Assessment where assessmentId = ?1")
    Optional<Assessment> findById(int assessmentId);
}


